<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Selfhelp\Controller;
use Think\Controller;

class BaseController extends Controller {
	/*
	 * 后台主页显示
	 */
	public function _initialize(){
// 		if(!strpos($_SERVER["HTTP_USER_AGENT"],"Chrome")){
// 			echo "<div style=\"color:#f00; font-size:15px; text-align:center; margin-top:24px;\">为保证后台能更好的展现效果，请使用谷歌Chrome浏览器或360浏览器极速模式</div>";
// 		}
		/*检测是否关注过并且登陆过*/
		if(empty(I('get.mtst'))){
			if(empty($_COOKIE['user_userinfo'])){
				header("Location:".C('LOGINADDRES').getURL());
				//header("Location:http://e.hrtv.cn/ehrtv/Login/index?url=".getURL());
			}
		}
		/*调用检测方法*/
		//$this->checkreg();
	}

	/*
	 * 检测是否注册
	 */
	public function checkreg(){
		$usertoken = $_COOKIE['user_userinfo'];
		$selfhelp = D(C('TABLE_SELFHELP'));
		$res = $selfhelp->where(array('user_token'=>$usertoken))->count();
		if($res<1){
			header("Location:/Selfhelp/Reg/index");
		}
	}

	/*
	 * 生成单个华人码
	 */
	public function qrcode($imgname,$data=null){
		if(!empty($data)){
			vendor("phpqrcode.phpqrcode");
			$object = new \QRcode();
			$level=3;
			$size=4;
			//容错级别
			$errorCorrectionLevel =intval($level);
			//生成图片大小
			$matrixPointSize = intval($size);
			$path = "IndexPublic/selfhelp/codeimg/";
			$fileName = $path.$imgname.'.png';
			$object->png($data, $fileName,  $errorCorrectionLevel, $matrixPointSize, 2);
			return $fileName;
		}else{
			return false;
		}

	}


}